<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>手机商城</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="{__STATIC__}/layuiAdmin/layui/css/layui.css" rel="stylesheet">
	<link href="{__STATIC__}/layuiAdmin/adminui/dist/css/admin.css" rel="stylesheet">
	<link href="{__STATIC__}/layuiAdmin/style/style.css" rel="stylesheet">
	<style>
		.layui-form-item img {
			width: 400px;
			height: auto;
		}
		.index_pic_ctr {
			position: absolute;
			width: 320px;
			height: auto;
			top: 60px;
			right: 20px;
			z-index: 999;
			background: #fff;
			padding: 10px;
		}
		.index_pic_ctr img {
			width: 100%;
			height: auto;
		}
		.close_ctr {
			position: absolute;
			width: 24px;
			height: 24px;
			line-height: 24px;
			text-align: center;
			border-radius: 12px;
			background: #eee;
			top: 0;
			right: 0;
			z-index: 9999;
			color: #333;
			font-size: 18px;
			cursor: pointer;
		}
	</style>
</head>
<body>
<div class="layui-fluid">
	<form class="layui-form" style="padding-bottom: 45px;">
		<div class="layui-card">
			<div class="layui-card-body" style="position: relative;">
				<div class="index_pic_ctr" id="index_pic">
					<div class="close_ctr" onclick="document.getElementById('index_pic').style.display = 'none';">×</div>
					<img src="/upload/pic/public/index.png">
				</div>
				<div class="layui-tab layui-tab-brief">
					<ul class="layui-tab-title">
						<li class="layui-this">手机商城</li>
					</ul>
					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">
							<div class="layui-form-item">
								<label class="layui-form-label">首页卡片：</label>
								<div class="layui-input-inline w120">
									<select name="m_open_card" lay-filter="m_card">
										<option value="1" {eq name="$setting.open_card" value="1"}selected{/eq}>开启</option>
										<option value="0" {eq name="$setting.open_card" value="0"}selected{/eq}>关闭</option>
									</select>
								</div>
							</div>
							<div id="span_card" {eq name="$setting.open_card" value="0"}style="display: none"{/eq}>
								<div class="layui-form-item">
									<label class="layui-form-label">卡片图片：</label>
									<div class="layui-input-inline">
										<input type="text" id="m_pic" name="m_card_pic" placeholder="请上传图片" class="layui-input" value="{$setting.card_pic}">
									</div>
									<div class="layui-btn-group">
										<button type="button" class="layui-btn layui-btn-info" id="btn_upload" style="padding-left: 10px;padding-right: 10px;">
											<i class="layui-icon">&#xe681;</i>上传
										</button>
										<button type="button" class="layui-btn layui-btn-info" id="btn_preview" style="padding-left: 10px;padding-right: 10px;">
											<i class="layui-icon">&#xe615;</i>预览
										</button>
									</div>
									<span style="display:none;" id="pic"><img id="yl_pic" src="/upload/pic/{$setting.card_pic}"></span>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">卡片链接1：</label>
									<div class="layui-input-inline">
										<input type="text" name="m_card_url1" placeholder="请输入链接地址" class="layui-input" value="{$setting.card_url1}">
									</div>
									<div class="layui-form-mid layui-word-aux">如：/pages/index/index</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">卡片链接2：</label>
									<div class="layui-input-inline">
										<input type="text" name="m_card_url2" placeholder="请输入链接地址" class="layui-input" value="{$setting.card_url2}">
									</div>
									<div class="layui-form-mid layui-word-aux">如：/pages/index/index</div>
								</div>
						    </div>
							<div class="layui-form-item">
								<label class="layui-form-label">分类样式：</label>
								<div class="layui-input-inline">
									<input type="radio" name="m_category_type" value="1" lay-filter="category_type" title="默认样式" {eq name="$setting.category_type" value="1"}checked{/eq}>
									<input type="radio" name="m_category_type" value="2" lay-filter="category_type" title="简洁样式" {eq name="$setting.category_type" value="2"}checked{/eq}>
								</div>
							</div>
							<div class="layui-form-item" id="span_pic1" {neq name="$setting.category_type" value="1"}style="display: none"{/neq}>
								<div class="layui-input-block">
									<img src="/upload/pic/public/category_type1.png">
								</div>
							</div>
							<div class="layui-form-item" id="span_pic2" {neq name="$setting.category_type" value="2"}style="display: none"{/neq}>
								<div class="layui-input-block">
									<img src="/upload/pic/public/category_type2.png">
								</div>
							</div>

						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="m_footer">
			<button class="layui-btn layui-btn-normal" lay-submit lay-filter="LAY-submit">提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
    </form>
</div>
</body>
</html>
<script src="{__STATIC__}/layuiAdmin/layui/layui.js"></script>
<script>
	layui.config({
		base: '{__STATIC__}/layuiAdmin/' // 静态资源所在路径
	}).use(['index','form','upload'], function(){
		let $ = layui.$;
		let layer = layui.layer;
		let upload = layui.upload;
		let form = layui.form;

		/* 监听select */
		form.on('select(m_card)',function (data) {
			if(data.value == 0){
				$("#span_card").hide();
			}
			else {
				$("#span_card").show();
			}
		});

		/* 监听radio */
		form.on('radio(category_type)',function (data) {
			if(data.value=='1'){
				$("#span_pic1").show();
				$("#span_pic2").hide();
			}
			if(data.value=='2'){
				$("#span_pic1").hide();
				$("#span_pic2").show();
			}
		});

		//上传
		upload.render({
			elem: '#btn_upload'
			,url: "{:url('upload/index')}"
			,data: {dir: 'card'}
			,accept: 'images'
			,before: function () {
				layer.load();
			}
			,done: function(res){
				layer.closeAll();
				if(res.code == 0) {
					$('#m_pic').val(res.data.file);
					$('#yl_pic').attr('src',res.data.src);
				}
				else {
					layer.msg(res.msg);
				}
			}
			,error: function(){
				layer.closeAll();
				layer.msg('请求异常');
			}
		});
		//预览
		$('#btn_preview').click(function () {
			layer.open({
				type: 1,
				shade: false,
				title: false,
				content: $('#pic')
			});
		});

		/* 监听提交 */
		form.on('submit(LAY-submit)', function(data){
			let field = data.field; //获取提交的字段
			$.ajax({
				type:"post",
				url:"saveMobile.html",
				data: {
					open_card:field.m_open_card,
					card_pic:field.m_card_pic,
					card_url1:field.m_card_url1,
					card_url2:field.m_card_url2,
					category_type:field.m_category_type
				},
				dataType:"json",
				beforeSend: function () {
					layer.load(1);
				},
				success:function(res){
					layer.closeAll(); //关闭弹层
					if(res.code == 0){
						layer.msg('修改成功', {
							time: 2000
						}, function(){
							location.reload();
						});
					}
					else {
						layer.msg(res.msg);
					}
				}
			});
			return false;
		});
	});
</script>